package org.example;

/**
 * IOC容器测试主类
 */
public class Main {
    public static void main(String[] args) {
        try {
            // 创建IOC容器，扫描org.example包下的配置类
            SimpleIOCContainer container = new SimpleIOCContainer("org.example");

            System.out.println("容器中Bean：" + String.join(", ", container.getBeanDefinitionNames()));

            // 1. 根据类型获取UserService Bean
            UserService userService = container.getBean(UserService.class);
            if (userService != null) {
                userService.doService();  // 调用Bean的方法
            }

            // 2. 根据名称获取字符串Bean
            String testBean = (String) container.getBean("testBean");
            System.out.println("获取到的testBean：" + testBean);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
